<style scoped>
.mask {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    opacity: 0.3;
    z-index: 9;
}

._ReviSion {
    position: fixed;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    width: 1234px;
    z-index: 99;
    background-color: white;
    overflow: auto;
}

.RS_top {
    height: 40px;
    background: #f8f8f8;
    display: flex;
    justify-content: space-between;
    padding: 10px 15px;
}

.RS_top p {
    font-weight: 700;
}

.RS_middle {
    padding: 0 15px;
    margin: 10px auto;
}

.RS_middle p {
    display: inline-block;
    width: 70px;
    text-align: right;
    margin-right: 10px;
}

.button_box {
    background: #f8f8f8;
    width: 100%;
    height: 60px;
    padding: 15px 0 15px 15px;
    display: flex;
    margin: 15px 0;
}

.inp_box {
    margin-bottom: 10px;
}

.inp_box2 {
    background: #f8f8f8;
    width: 100%;
    height: 60px;
    padding: 15px 0;
    margin: 15px 0;
}

.RS_button {
    margin-left: 1070px;
}
</style>

<style>
.vendorOrderReviSion .el-input__inner {
    height: 30px;
    width: 160px;
}
.vendorOrderReviSion .el-input {
  display: inline;
}
.vendorOrderReviSion .el-icon-date{
  line-height: 23px!important;
}
</style>

<template>
  <div class="vendorOrderReviSion">
    <div class="mask"></div>
    <div class="_ReviSion">
      <div class="RS_top">
        <p>改单(厂商订货)</p>
        <i @click="closeRevision" class="el-icon-close"></i>
      </div>
      <div class="RS_middle">
        <div class="button_box">
          <el-button type="primary" icon="el-icon-search" @click="search">查询</el-button>
          <el-button icon="el-icon-edit-outline" @click="modification(0)">改单</el-button>
        </div>
        <div class="inp_box">
          <p>订货日期</p>
          <el-date-picker v-model="inputDate1" type="date" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          <p>预交日期</p>
          <el-date-picker v-model="inputDate2" type="date" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          <p>单号</p>
          <el-input v-model="odd"></el-input>
          <p>售价</p>
          <el-input v-model="sellingPrice" disabled></el-input>
          <p>厂商编号</p>
          <el-input v-model="manufacturer" disabled></el-input>
        </div>
        <div class="inp_box">
          <p>数量</p>
          <el-input v-model="sum"></el-input>
          <p>厂订序号</p>
          <el-input v-model="inputSequence" disabled></el-input>
          <p>货号</p>
          <el-input v-model="kindsNumber" disabled></el-input>
          <p>单价</p>
          <el-input v-model="onePrice"></el-input>
        </div>
        <div class="inp_box2">
          <p>货号</p>
          <el-input v-model="searchKindsNumber"></el-input>
          <p>厂订序号</p>
          <el-input v-model="searchInputSequence"></el-input>
        </div>
        <el-table height="250" :data="tableData" highlight-current-row :header-cell-style="{background:'#f4f4f4',padding:0,height:'40px'}" :cell-style="{padding:0,height:'36px'}" style="width: 100%" @row-click="rowClick">
          <el-table-column type="index" label="序号" width="50"></el-table-column>
          <el-table-column prop="orderSalesSequence" label="厂订序号"></el-table-column>
          <el-table-column prop="" label="单号" width="120"></el-table-column>
          <el-table-column prop="manufacturerNo" label="厂商编号" width="80"></el-table-column>
          <el-table-column prop="kindsNumber" label="货号" width="160"></el-table-column>
          <el-table-column prop="totalSum" label="数量" width="80"></el-table-column>
          <el-table-column prop="" label="单价" width="100"></el-table-column>
          <el-table-column prop="totalMoney" label="金额" width="100"></el-table-column>
          <el-table-column prop="orderTime" label="订货日期" width="160"></el-table-column>
          <el-table-column prop="" label="预定日期" width="160"></el-table-column>
        </el-table>
      </div>
      <!-- <el-button @click="closeRevision" class="RS_button">取消</el-button>
      <el-button type="primary" @click="modification(1)">保存</el-button> -->
    </div>
  </div>
</template>
<script>
import { orderQuery, modify } from '../../../../network/manufacturerOrder'

import today from '../../../../components/mixins/today'

export default {
  mixins: [today],
  props: {
    selectInputSequence: {
      type: String,
      default: ''
    },
    manufacturerList: {
      type: Array,
      default: []
    },
    flag: {
      type: Boolean,
      default: false
    }
  },
  data(){
    return{
      inputDate1: '',
      inputDate2: '',
      odd: '',
      sellingPrice: '',
      manufacturer: '',
      sum: '',
      inputSequence: '',
      kindsNumber: '',
      onePrice: '',

      searchKindsNumber: '',
      searchInputSequence: '',

      tableData: [],
      updateData: {}
    }
  },
  watch: {
    flag(a,b){
      if (a && this.selectInputSequence) this.search()
    },
    selectInputSequence(a,b){
      this.searchInputSequence = a
    },
  },
  methods:{
    clearData(){
      this.inputDate1 = ''
      this.inputDate2 = ''
      this.odd = ''
      this.sellingPrice = ''
      this.manufacturer = ''
      this.sum = ''
      this.inputSequence = ''
      this.kindsNumber = ''
      this.onePrice = ''
      
      this.searchKindsNumber = ''
      this.searchInputSequence = ''
      this.tableData = []
    },
    closeRevision(){
      this.$emit('closeRevision')
      this.clearData()
    },

    // isNewBuild是0不能改数量，别的都可以改
    rowClick(row){
      // console.log(row)
      this.updateData = row
      
      this.inputDate1 = row.orderTime
      this.inputDate2 = row.prepayTime
      this.receiptsNumber = row.receiptsNumber
      this.sellingPrice = row.sellingPrice
      this.manufacturerNo = row.manufacturerNo
      this.sum = row.number
      this.inputSequence = row.orderSalesSequence
      this.kindsNumber = row.kindsNumber
      this.onePrice = row.onePrice
    },

    // 查询
    search(){
      if (!this.searchInputSequence && !this.searchKindsNumber) {
        this.$alert('请输入查询条件', '', {
          confirmButtonText: '确定'
        })
        return
      }
      // S2020090200002
      let d = {
        orderSalesSequence: this.searchInputSequence,
        kindsNumberStr: this.searchKindsNumber ? `%${this.searchKindsNumber}%` : ''
      }
      orderQuery(JSON.stringify(d)).then(res => {
        if (res.data.code == 200) {
          this.tableData = []
          for (const key in res.data.data) {
            if (res.data.data.hasOwnProperty(key)) {
              const receiptsNumber = res.data.data[key].receiptsNumber
              res.data.data[key].manufacturerOrderInfoOneVOList.forEach(e => {
                e.orderTimeShort = e.orderTime.slice(0,10)
                e.prepayTimeShort = e.prepayTime.slice(0,10)
                e.receiptsNumber = receiptsNumber
                this.tableData.push(e)
              })
            }
          }
        }
      })
    },

    
    modification(f){
      if (JSON.stringify(this.updateData) == '{}') {
        this.$alert('请选择一条数据修改', '', {
          confirmButtonText: '确定'
        })
        return
      }
      if (!this.inputDate1) {
        this.$alert('订货日期不能为空', '', {
          confirmButtonText: '确定'
        })
        return
      }
      if (!this.inputDate2) {
        this.$alert('预交日期不能为空', '', {
          confirmButtonText: '确定'
        })
        return
      }
      if (!String(this.sum)) {
        this.$alert('数量不能为空', '', {
          confirmButtonText: '确定'
        })
        return
      }
      if (!String(this.onePrice)) {
        this.$alert('单价不能为空', '', {
          confirmButtonText: '确定'
        })
        return
      }

      this.updateData.sequence = this.inputSequence
      this.updateData.orderTime = this.inputDate1
      this.updateData.prepayTime = this.inputDate2
      this.updateData.orderSalesSequence = this.receiptsNumber
      this.updateData.receiptsNumber = this.receiptsNumber
      this.updateData.number = this.sum
      this.updateData.onePrice = this.onePrice

      // console.log(this.updateData)
      modify(JSON.stringify(this.updateData)).then(res => {
        if (res.data.code == 200) {
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.search()
        } else {
          this.$message.error('修改失败')
          this.search()
        }
      })
    },
  }
}
</script>